#include "ItemRoot.h"
#include "Defines.h"



namespace
{
QString FILEPATH_FIELD_NAME = "filepath";
}



ItemRoot::ItemRoot(QObject *parent) :
    ItemGroup(parent)
{
    setData(CategoryData, ItemCategory_Root);

    m_dirty = false;

    connect(this, SIGNAL(sigDirty()), this, SLOT(setDirty()));
}



ItemRoot::ItemRoot(const QString& name, QObject *parent) :
    ItemGroup(parent)
{
    setData(CategoryData, ItemCategory_Root);
    setData(NameData, name);

    m_dirty = false;

    connect(this, SIGNAL(sigDirty()), this, SLOT(setDirty()));
}



void ItemRoot::setFilePath(const QString &file_path)
{
    setData(FileData, file_path);
}



QString ItemRoot::filePath() const
{
    return data(FileData).toString();
}



int ItemRoot::fieldCount() const
{
    return (ItemRoot::DataType_LAST - AbstractItem::DataType_FIRST + 1);
}



QString ItemRoot::fieldName(const int &data_type) const
{
    switch (data_type)
    {
    case ItemRoot::FileData: return FILEPATH_FIELD_NAME;
    }

    return AbstractItem::fieldName(data_type);
}



int ItemRoot::field(const QString &field_name) const
{
    if (field_name == FILEPATH_FIELD_NAME) return FileData;

    return AbstractItem::field(field_name);
}



bool ItemRoot::isDirty() const
{
    return m_dirty;
}



void ItemRoot::setDirty(const bool &dirty)
{
    m_dirty = dirty;
}



void ItemRoot::setCustomData(const int &data_type, const QVariant &value)
{
    switch (data_type)
    {
    case FileData:
        m_filePath = value.toString();
        return;
    }
}



QVariant ItemRoot::customData(const int &data_type, int) const
{
    switch (data_type)
    {
    case FileData:
        return m_filePath;
    }

    return QVariant();
}



